package cn.bs.seckill.controller;


import cn.bs.seckill.service.UserService;
import cn.bs.seckill.vo.LoginVo;
import cn.bs.seckill.vo.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Controller
//@RestController 返回的是类里面的东西,Controller才是跳转到静态资源
@Slf4j
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private UserService userService;

    //跳转登录页面
    @RequestMapping("/login")
    public String longin(){
        return "login";
    }
//@Valid才能触发303
    @ResponseBody
    @RequestMapping("/doLogin")
    public RespBean doLogin(@Valid LoginVo loginVo, HttpServletRequest request, HttpServletResponse response){
//        log.info("{}",loginVo);
        return userService.doLogin(loginVo,request,response);
    }

}
